package com.xzlf.conttoller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xzlf.config.R;
import com.xzlf.entity.TbUser;
import com.xzlf.service.TbUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private TbUserService tbUserService;

    @GetMapping("/list")
    public R<List<TbUser>> list(String username){
        List<TbUser> list = tbUserService.list(new LambdaQueryWrapper<TbUser>()
                .likeRight(StringUtils.isNotBlank(username), TbUser::getUsername, username));
        return R.ok(list);
    }

    @PostMapping("/page")
    public R<Page<TbUser>> list(Long current, Long size, String username){
        Page<TbUser> page = tbUserService.page(current, size, username);
        return R.ok(page);
    }
}

